/**
 * Created by charsen on 16/6/14.
 */
/**
 * Created by charsen on 16/6/7.
 */
directives.directive('priceTrend', ["$rootScope", "tools", "$timeout", function ($rootScope, tools, $timeout) {
    return {
        restrict: 'AE',
        scope: {},
        replace: true,
        link: function (scope, element, attr) {
            $rootScope.$on('PRICE_TREND_EV', function (e, option, name,plant,index) {
                $(element).modal('show');
                scope.title = name;
                scope.subtitle= "数据来自"+plant;
                scope.plant=plant;
                console.log(scope.title,scope.palnt);
                if(index==0){
                    $(element).find('.taobao').highcharts({
                        title: {
                            text: scope.title,
                            x: -20 //center
                        },
                        subtitle: {
                            text: "数据来自"+scope.plant,
                            x: -20
                        },
                        xAxis: {
                            categories: ['7-1', '7-2', '7-3', '7-4', '7-5', '7-6', '7-7', '7-8', '7-9', '7-10', '7-11', '7-12']
                        },
                        yAxis: {
                            title: {
                                text: '元'
                            },
                            plotLines: [{
                                value: 0,
                                width: 1,
                                color: '#808080'
                            }]
                        },
                        tooltip: {
                            valueSuffix: '°C'
                        },
                        legend: {
                            layout: 'vertical',
                            align: 'right',
                            verticalAlign: 'middle',
                            borderWidth: 0
                        },
                        series: [{
                            name: scope.plant,
                            data: [1666, 1699, 1600, 1454, 1525, 1456, 1489, 1665, 1560, 1450, 1393, 1399]
                        }]
                    });

                }else{
                    $(element).find('.taobao').highcharts({
                        title: {
                            text: scope.title,
                            x: -20 //center
                        },
                        subtitle: {
                            text: "数据来自"+scope.plant,
                            x: -20
                        },
                        xAxis: {
                            categories: ['7-1', '7-2', '7-3', '7-4', '7-5', '7-6', '7-7', '7-8', '7-9', '7-10', '7-11', '7-12']
                        },
                        yAxis: {
                            title: {
                                text: '元'
                            },
                            plotLines: [{
                                value: 0,
                                width: 1,
                                color: '#808080'
                            }]
                        },
                        tooltip: {
                            valueSuffix: '°C'
                        },
                        legend: {
                            layout: 'vertical',
                            align: 'right',
                            verticalAlign: 'middle',
                            borderWidth: 0
                        },
                        series: [{
                            name: scope.plant,
                            data: [138, 235, 146, 299, 236, 286, 272, 263, 241, 220, 245, 255]
                        }]
                    });
                }
        });
            scope.ok = function () {
                $(element).modal('hide');
            };
            scope.cancel = function () {
                $(element).modal('hide');
            };


            var config = {
                title: scope.title,
                subtitle: scope.palnt
            };



            var dateRange = new pickerDateRange('date_demo3', {
                aRecent7Days: 'aRecent7DaysDemo3', //最近7天
                isTodayValid: false,
                startDate: '2016-07-1',
                endDate: '2016-07-2',
                //needCompare : true,
                //isSingleDay : true,
                //shortOpr : true,
                defaultText: ' 至 ',
                inputTrigger: 'input_trigger_demo3',
                theme: 'ta',
                success: function (obj) {
                    $("#dCon_demo3").html('开始时间 : ' + obj.startDate + '<br/>结束时间 : ' + obj.endDate);
                }
            });




        },
        templateUrl: "/trend-new-BI/app/components/priceMonitor/priceTrend/priceTrendView.html"
    }
}]);